<?php
function resizeImage($original, $toWidth, $toHeight){
	list($width, $height) = getimagesize($original);
	$xscale = $width/$toWidth;
	$yscale = $height/$toHeight;

	if ($yscale>$xscale){
		$new_width = round($width * (1/$yscale));
		$new_height = round($height * (1/$yscale));
	}else {
		$new_width = round($width * (1/$xscale));
		$new_height = round($height * (1/$xscale));
	}

	$resized = imagecreatetruecolor($toWidth, $toHeight);
	$tmp = imagecreatefromstring($original);
	imagecopyresampled($resized, $tmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

	ob_start();
	imagejpeg($resized);
	$new_blob = ob_get_clean();

	return $new_blob;
}
